﻿using B.S.DataBase.MyProject.Domain.wdx;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.BasicSettings;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.BasicSettings
{
    public class GetIndexClassDetailCommandHandler : IRequestHandler<GetIndexClassDetailCommand, APIResult<IndexClass>>
    {
        /// <summary>
        /// SqlSugar
        /// </summary>
        private readonly SqlSugarContext sqlSugar;
        /// <summary>
        /// 构造方法
        /// </summary>
        public GetIndexClassDetailCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }
        public Task<APIResult<IndexClass>> Handle(GetIndexClassDetailCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<IndexClass> result = new APIResult<IndexClass>();
                var list = sqlSugar.db.Queryable<IndexClass>().First(x => x.IndexClass_Id == request.IndexClass_Id);
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = list;
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
